feat: add comprehensive energy unit conversion module #1014
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR adds a new
energyconversion module to the conversions library, enabling conversion between 70+ energy units across different measurement systems and scientific disciplines.Implementation
Design Decisions
to_joule()→joule_to_unit()for clarity and maintainabilityEnergyUnitenum matching the repository'stemperature.rspattern for compile-time safetyJoule | WattSecond | NewtonMeter) for cleaner codeSupported Units (70+ units)
SI Units (8)
Power-Time Units (6)
Mechanical Units (3)
Calorie Variants (6)
Electron Volt Units (3)
British Thermal Units (3)
Imperial Force-Distance Units (7)
Horsepower Units (2)
Metric Force Units (5)
Therm Units (3)
Specialized Units (7)
Atomic Units (2)
Testing
Test Coverage
Test Organization
All tests use the
approx_eq()helper for floating-point comparisons with appropriate tolerances, ensuring robust validation across the full range of energy scales from attojoules to gigatons.Verification
Code Quality
f64for all calculations with appropriate tolerance checks (EPSILON = 1e-10)temperature.rsmodule patternExamples
References
All conversion factors are based on authoritative sources:
Checklist
cargo clippypasses with zero warnings)cargo testshows 100% pass rate)temperature.rs)mod.rswith proper exports